<!DOCTYPE html>
<html>
<head>
    <base href="<%=basePath %>"><!-- 整个页面全部指定为这个地址 -->
    <meta charset="UTF-8">
    <title>申请审核咨询页面</title>
    <link rel="stylesheet" href="../../layui/css/layui.css" media="all">
    <script type="text/javascript" src="../../res/js/Tools.js"></script>
    <script src="../../res/js/jquery-3.4.1.min.js" type="text/javascript"
            charset="utf-8"></script>
    <script src="../../js/login_common.js" charset="utf-8"></script>
    <script src="../../layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript">
        //全局同步
        $.ajaxSetup({
            async : false
        });
        $(function(){
            var creater=loginObj.user.userName;
            $("#creater").val(creater);

        })
    </script>
</head>
<body>
<form class="layui-form" action="" id="formDId" lay-filter="example" method="post" enctype="multipart/form-data">
    <input type="hidden" id="creater" name="creater" />
    <input type="hidden" id="saId" name="saId" />
    <input type="hidden" id="saName" name="saName" />
    <input type="hidden" id="type" name="type" />
    <div class="layui-inline">
        <label class="layui-form-label">选择主专家</label>
        <div class="layui-input-inline">
            <select id="expertId" name="expertId"   lay-verify="required">
            </select>
        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label">申请理由</label>
        <div class="layui-input-block" style="margin-top: 10px">
            <textarea placeholder="请输入申请理由" required lay-verify="required" class="layui-textarea" name="applyForExp" id="applyForExp"></textarea>
        </div>
    </div>





    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="button" class="layui-btn site-demo-active" lay-submit lay-filter="formDemo">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
<script type="text/javascript">
    var form=null;
    layui.use('form', function(){
        form = layui.form;
        //监听提交
        form.on('submit(formDemo)', function(data){
            var type=$("#type").val();
            if(type){
                layer.confirm("中心领导不通过!您确定要再次申请吗?", function (index) {
                    //先查询一遍是否提交审核和专家咨询了
                    var urlone="../../../mentalTrainingController/updateStateTwo";
                    var schemeIdone = getQueryString("id");
                    var applyForExp=$("#applyForExp").val();
                    var expertId=$("#expertId").val();
                    var saName=$("#saName").val();
                    var dataone={applyForExp:applyForExp,expertId:expertId,saName:saName,schemeId:schemeIdone};
                    // 单击之后提交按钮不可选,防止重复提交
                    var DISABLED = 'layui-btn-disabled';
                    // 增加样式
                    $('.site-demo-active').addClass(DISABLED);
                    // 增加属性
                    $('.site-demo-active').attr('disabled', 'disabled');
                    $.post(urlone,dataone,function(objone){
                        if(objone.num==1){
                            layer.msg(objone.msg,{time:3000,icon:6},function(){
                                parent.layui.table.reload("test");
                                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                parent.layer.close(index); //再执行关闭/再执行关闭
                            });
                        }
                    },"json");
                });
            }else{
                //先查询一遍是否提交审核和专家咨询了
                var urll="../../../mentalTrainingController/selectState";
                var schemeId = getQueryString("id");
                var dataone={schemeId:schemeId};
                $.post(urll,dataone,function(obj){
                    if(obj.num==1){
                        layer.confirm("审核和申请已经提交过，是否进行修改操作", function (index) {
                            var urlTwo="../../../mentalTrainingController/updateState";
                            var applyForExp=$("#applyForExp").val();
                            var expertId=$("#expertId").val();
                            var saName=$("#saName").val();
                            var saId=$("#saId").val();
                            var dataTwo={applyForExp:applyForExp,expertId:expertId,saName:saName,saId:saId};
                            // 单击之后提交按钮不可选,防止重复提交
                            var DISABLED = 'layui-btn-disabled';
                            // 增加样式
                            $('.site-demo-active').addClass(DISABLED);
                            // 增加属性
                            $('.site-demo-active').attr('disabled', 'disabled');
                            $.post(urlTwo,dataTwo,function(obj){
                                if(obj.num==1){
                                    layer.msg(obj.msg,{
                                        icon:6,
                                        time:1000 //1秒关闭(如果不配置默认三秒)
                                    },function(){
                                        //关闭当前层
                                        //当你在iframe页面关闭自身时
                                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                        parent.layer.close(index); //再执行关闭
                                        //刷新父页面
                                        //parent.location.reload();
                                    });
                                    return false ;
                                }
                            },"json");
                        });
                    }else{
                        var formData = new FormData(document.getElementById("formDId"));
                        var url="../../../mentalTrainingController/expertone";
                        // 单击之后提交按钮不可选,防止重复提交
                        var DISABLED = 'layui-btn-disabled';
                        // 增加样式
                        $('.site-demo-active').addClass(DISABLED);
                        // 增加属性
                        $('.site-demo-active').attr('disabled', 'disabled');
                        $.ajax({
                            url:url,
                            type:"post",
                            data:formData,
                            processData:false,
                            contentType:false,
                            dataType:"json",
                            success:function(obj){
                                if(obj.num==1){
                                    layer.msg(obj.msg,{
                                        icon:6,
                                        time:1000 //1秒关闭(如果不配置默认三秒)
                                    },function(){
                                        //关闭当前层
                                        //当你在iframe页面关闭自身时
                                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                        parent.layer.close(index); //再执行关闭
                                        //刷新父页面
                                        //parent.location.reload();
                                    });
                                    return false ;
                                }
                            },
                            error:function(e){
                                layer.msg("错误！！");
                            }
                        });
                    }
                },"json");
            }

            return false;
        });
        var ide = getQueryString("id");
        var type = getQueryString("type");
       if(type){
           $("#type").val(type);
       }
        if(ide){
            //根据主键查询名字
            var data={schemeId:ide};
            $("#saId").val(ide);
            var url="../../../mentalTrainingController/selectByPrimaryKeyOne";
            $.post(url,data,function(obj){
                $("#saName").val(obj.schemeName);
            },"json");
            loadType();//加载下拉框
            findById();//修改页面的赋值
        }
    });

    function loadType() {
        //加载下拉框
        var url="../../../mentalTrainingController/findAlltwo";
        var data=null;
        $.post(url,data,function(obj){
            $.each(obj,function(index,item){
                $("#expertId").append("<option value='"+item.expertId+"'>"+item.expertName+"</option>");
            });
            form.render('select');
        },"json");
    }

    //修改页面的赋值
    function findById(){
        var id=getQueryString("id");
        var urlone="../../../mentalTrainingController/findstateOne";
        var data={schemeId:id};
        $.post(urlone,data,function(objs){
            $("#expertId").val(objs.expertId);
            $("#applyForExp").val(objs.applyForExp);
            form.render('select');
        },"json");
    }
</script>
</body>
</html>